/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AccessManager.AttrRightChecker;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.AttributeClass;
/*     */ import com.zimbra.cs.account.AttributeManager;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.service.account.ToXML;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetCos
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  52 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  58 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  59 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  61 */     Set<String> reqAttrs = getReqAttrs(request, AttributeClass.cos);
/*     */     
/*  63 */     Element d = request.getElement("cos");
/*  64 */     String key = d.getAttribute("by");
/*  65 */     String value = d.getText();
/*     */     
/*  67 */     Cos cos = prov.get(Key.CosBy.fromString(key), value);
/*     */     
/*  69 */     if (cos == null) {
/*  70 */       throw AccountServiceException.NO_SUCH_COS(value);
/*     */     }
/*  72 */     AdminAccessControl aac = checkCosRight(zsc, cos, AdminRight.PR_ALWAYS_ALLOW);
/*     */     
/*  74 */     Element response = zsc.createElement(AdminConstants.GET_COS_RESPONSE);
/*  75 */     encodeCos(response, cos, reqAttrs, aac.getAttrRightChecker(cos));
/*     */     
/*  77 */     return response;
/*     */   }
/*     */   
/*     */   public static void encodeCos(Element e, Cos c) throws ServiceException {
/*  81 */     encodeCos(e, c, null, null);
/*     */   }
/*     */   
/*     */   public static void encodeCos(Element e, Cos c, Set<String> reqAttrs, AccessManager.AttrRightChecker attrRightChecker) throws ServiceException {
/*  85 */     Config config = Provisioning.getInstance().getConfig();
/*  86 */     Element cos = e.addNonUniqueElement("cos");
/*  87 */     cos.addAttribute("name", c.getName());
/*  88 */     cos.addAttribute("id", c.getId());
/*     */     
/*  90 */     if (c.isDefaultCos()) {
/*  91 */       cos.addAttribute("isDefaultCos", true);
/*     */     }
/*  93 */     Map attrs = c.getUnicodeAttrs();
/*  94 */     AttributeManager attrMgr = AttributeManager.getInstance();
/*  95 */     for (Iterator mit = attrs.entrySet().iterator(); mit.hasNext();) {
/*  96 */       Map.Entry entry = (Map.Entry)mit.next();
/*  97 */       String name = (String)entry.getKey();
/*  98 */       Object value = entry.getValue();
/*     */       
/* 100 */       if ((reqAttrs == null) || (reqAttrs.contains(name)))
/*     */       {
/*     */ 
/* 103 */         boolean allowed = attrRightChecker == null ? true : attrRightChecker.allowAttr(name);
/*     */         
/* 105 */         boolean isCosAttr = !attrMgr.isAccountInherited(name);
/* 106 */         if ((value instanceof String[])) {
/* 107 */           String[] sv = (String[])value;
/* 108 */           for (int i = 0; i < sv.length; i++) {
/* 109 */             encodeCosAttr(cos, name, sv[i], isCosAttr, allowed);
/*     */           }
/* 111 */         } else if ((value instanceof String)) {
/* 112 */           value = ToXML.fixupZimbraPrefTimeZoneId(name, (String)value);
/* 113 */           encodeCosAttr(cos, name, (String)value, isCosAttr, allowed);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private static void encodeCosAttr(Element parent, String key, String value, boolean isCosAttr, boolean allowed) {
/* 120 */     Element e = parent.addNonUniqueElement("a");
/* 121 */     e.addAttribute("n", key);
/*     */     
/* 123 */     if (allowed) {
/* 124 */       e.setText(Provisioning.sanitizedAttrValue(key, value).toString());
/*     */     } else {
/* 126 */       e.addAttribute("pd", true);
/*     */     }
/*     */     
/* 129 */     if (isCosAttr) {
/* 130 */       e.addAttribute("c", true);
/*     */     }
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 136 */     relatedRights.add(Rights.Admin.R_getCos);
/* 137 */     notes.add(String.format("Attributes that are not allowed to be get by the authenticated admin will be returned as <a n=\"{attr-name}\" pd=\"1\"/>.To allow an admin to get all attributes, grant the %s right", new Object[] { Rights.Admin.R_getCos.getName() }));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetCos.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */